package com.ruoyi.eduadmin.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.eduadmin.domain.TAttention;
import com.ruoyi.eduadmin.mapper.TAttentionMapper;
import com.ruoyi.student.api.StudentService;
import com.ruoyi.student.api.domain.TStudent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.eduadmin.mapper.TTeachTraceMapper;
import com.ruoyi.eduadmin.domain.TTeachTrace;
import com.ruoyi.eduadmin.service.ITTeachTraceService;

/**
 * 教学追踪Service业务层处理
 * 
 * @author hyk
 * @date 2022-12-26
 */
@Service
public class TTeachTraceServiceImpl implements ITTeachTraceService 
{
    @Autowired
    private TTeachTraceMapper tTeachTraceMapper;

    @Autowired
    private TAttentionMapper tAttentionMapper;

    @Autowired
    private StudentService studentService;

    /**
     * 查询教学追踪
     * 
     * @param id 教学追踪主键
     * @return 教学追踪
     */
    @Override
    public TTeachTrace selectTTeachTraceById(Long id)
    {
        return tTeachTraceMapper.selectTTeachTraceById(id);
    }

    /**
     * 查询教学追踪列表
     * 
     * @param tTeachTrace 教学追踪
     * @return 教学追踪
     */
    @Override
    public List<TTeachTrace> selectTTeachTraceList(TTeachTrace tTeachTrace)
    {
        return tTeachTraceMapper.selectTTeachTraceList(tTeachTrace);
    }

    /**
     * 新增教学追踪
     * 
     * @param tTeachTrace 教学追踪
     * @return 结果
     */
    @Override
    public int insertTTeachTrace(TTeachTrace tTeachTrace)
    {
        AjaxResult ajaxResult = studentService.findStudentByName(tTeachTrace.getStudentName());
        if (!ajaxResult.isSuccess()){
            throw new ServiceException("获取失败！");
        }
        Object data = ajaxResult.get("data");
        if (data == null){
            throw new ServiceException("获取失败！");
        }
        TStudent tStudent = JSONObject.parseObject(JSONObject.toJSONString(data), TStudent.class);

        tTeachTrace.setStudentId(tStudent.getId());
        System.out.println(tTeachTrace);
        return tTeachTraceMapper.insertTTeachTrace(tTeachTrace);
    }


    /**
     * 修改教学追踪
     * 
     * @param tTeachTrace 教学追踪
     * @return 结果
     */
    @Override
    public int updateTTeachTrace(TTeachTrace tTeachTrace)
    {
        return tTeachTraceMapper.updateTTeachTrace(tTeachTrace);
    }

    /**
     * 批量删除教学追踪
     * 
     * @param ids 需要删除的教学追踪主键
     * @return 结果
     */
    @Override
    public int deleteTTeachTraceByIds(Long[] ids)
    {
        return tTeachTraceMapper.deleteTTeachTraceByIds(ids);
    }

    /**
     * 删除教学追踪信息
     *
     * @param id 教学追踪主键
     * @return 结果
     */
    @Override
    public int deleteTTeachTraceById(Long id)
    {
        return tTeachTraceMapper.deleteTTeachTraceById(id);
    }

    @Override
    public List<TTeachTrace> selectTeacherTrace(Long id) {

        return tTeachTraceMapper.selectTeacherTrace(id);
    }
}
